import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../controllers/tabs_controller.dart';

class TabsView extends GetView<TabsController> {
  const TabsView({super.key});

  //body部件
  Widget pageViewWidget() {
    Widget content = PageView(
      controller: controller.pageController,
      onPageChanged: (index) => {controller.currIndex.value = index},
      children: controller.pageList,
    );
    return content;
  }

  //底部导航栏部件
  BottomNavigationBar bottomNavigationBarWidget() {
    BottomNavigationBar content = BottomNavigationBar(
      items: controller.bottomNavigationBarItemList,
      currentIndex: controller.currIndex.value,
      type: BottomNavigationBarType.fixed,
      selectedItemColor: Colors.deepOrange,
      unselectedItemColor: Colors.blueGrey,
      onTap: (index) {
        debugPrint('click index: ${index}');
        controller.currIndex.value = index;
        controller.pageController.jumpToPage(controller.currIndex.value);
      },
    );
    return content;
  }

  @override
  Widget build(BuildContext context) {
    return Obx(
      () => Scaffold(
        body: pageViewWidget(),
        bottomNavigationBar: bottomNavigationBarWidget(),
      ),
    );
  }
}
